<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'account.label', default: 'account')}"/>
    <title>楼盘评分</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <style>
    .distance > .row {
        margin-bottom: 10px;
    }
    #word>a{
        border-radius: 0!important;
    }
    #searchCondition{
        border-radius: 0!important;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">
<div class="landing-page">
    <div class="small-header">
        <div class="hpanel">
            <div class="panel-body">
                <div id="hbreadcrumb" class="pull-right">
                    <ol class="hbreadcrumb breadcrumb">
                        <li>CINDATA PLS</li>
                        <li class="active">
                            <span>楼盘评分</span>
                        </li>
                    </ol>
                </div>

                <h2 class="font-light m-b-xs">
                    楼盘评分
                </h2>
            </div>
        </div>
    </div>

    <header id="page-top">
        <div class="container">
            <div class="heading">
                <h1>
                    房地产大数据多维度楼盘评分
                </h1>
                <span>Multi-Dimension house grading base on estate big data</span>

                <p class="small">
                    基于大数据和智能模型，从多维度对每个楼盘评分。贷前准入、贷中风控、贷后管理都可将此评分作为重要依据。
                </p>
            </div>

            <div class="form-group">
                <div class="row">
                    <g:form method="POST" action="" class="form-horizontal" role="form" id="form">
                        <div class="panel-body">
                            <div class="row">
                                <div class="form-group col-sm-2" style="margin:0;">
                                    <g:select class="form-control" name="city" id="city" from="${com.cindata.User.findById(session.SPRING_SECURITY_CONTEXT.authentication.principal.id)?.account?.citys*.city.sort{a, b -> a.id < b.id ? -1 : 1 }}"
                                            valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name" value="${params?.city}"/>
                                </div>
                                <div class="form-group col-sm-6 col-sm-offset-1">
                                    <input type="text" class="form-control" name="searchCondition" id="searchCondition"
                                           value="${params?.searchCondition}" placeholder="请输入小区名称或地址">

                                    <div id="word"></div>
                                </div>
                            </div>
                        </div>
                    </g:form>
                </div>
            </div>
        </div>
    </header>
</div>
<script>

    $(function () {
        var tempkey = "";
        //当键盘键被松开时发送Ajax获取数据
        $('#searchCondition').keyup(function () {
            var keywords = $(this).val();
            var city = $('#city').val();
            if (keywords == '') {
                $('#word').hide();
                return
            };
            //还是要减少下请求次数的
            if (tempkey == keywords){
                return
            }else{
                tempkey =  keywords
            }
            $.ajax({
                url: '/buildingsRated/searchBuilding',
                data: {
                    keywords: keywords,
                    city: city
                },
                dataType: 'json',
                //jsonp: 'cb', //回调函数的参数名(键值)key
                // jsonpCallback: 'fun', //回调函数名(值) value
                beforeSend: function () {
                    $('#word').append('<div class="form-control">正在加载。。。</div>');
                },
                success: function (parameter) {
                    $('#word').empty().show();
                    if (parameter.s == '' || parameter.s == null) {
                        $('#word').append('<div class="error form-control">未找到  "' + keywords + '"</div>');
                    }
                    var i = -1;
                    $.each(parameter.s, function () {
                        i++;
                        $('#word').append('<a href="javascript:void(0);" data-city="'+parameter.city+'" data-cid = "' + parameter.id[i] + '" class="click_work form-control">' + this + '</a>');
                    })
                },
                error: function () {
                    $('#word').empty().show();
                    $('#word').append('<div class="form-control">Fail "' + keywords + '"</div>');
                }
            })
        })
        //点击搜索数据复制给搜索框
        $(document).on('click', '.click_work', function () {
            var id = $(this).attr("data-cid");
            var city = $(this).attr("data-city");
            $.ajax({
                url: '/buildingsRated/hasScore',
                data: {
                    id : id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('body').append('<div id = "tanchu"  style=" top:0px;left:0px;width: 100%;height: 100%;position: fixed;z-index: 99;background: gray; opacity: 0.4;"><img src="/assets/loading.gif" style="position: fixed;z-index: 99;left: 50%;top: 50%;"/></div>');
                },
                success: function (data) {
                    if(data.score.closingScore){
                        location.href= "circulationAssessment?id="+id+"&city="+city;
                    } else {
                        toastr.error('此小区没有流动性评分！');
                        $("#tanchu").remove();
                    }
                },
                error: function () {
                    toastr.error('网络故障！');
                    $("#tanchu").remove();
                }
            })

        })
    })
</script>
</body>
</html>
